<?php
require_once 'config/database.php';

echo "<h2>数据库用户检查</h2>";

// 检查users表是否存在
$sql = "SHOW TABLES LIKE 'users'";
$result = $conn->query($sql);

if ($result->num_rows == 0) {
    echo "❌ users表不存在，请先运行install.php<br>";
    die();
}

// 查询所有用户
$sql = "SELECT id, username, role, created_at FROM users";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    echo "✅ 找到 " . $result->num_rows . " 个用户账号<br><br>";
    echo "<table border='1' style='border-collapse: collapse; padding: 5px;'>";
    echo "<tr><th>ID</th><th>用户名</th><th>角色</th><th>创建时间</th></tr>";
    
    while($row = $result->fetch_assoc()) {
        echo "<tr>";
        echo "<td>" . $row['id'] . "</td>";
        echo "<td>" . $row['username'] . "</td>";
        echo "<td>" . $row['role'] . "</td>";
        echo "<td>" . $row['created_at'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
} else {
    echo "❌ 数据库中没有用户账号<br>";
}

// 特别检查admin账户
$sql = "SELECT * FROM users WHERE username = 'admin'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $admin = $result->fetch_assoc();
    echo "<br>✅ 管理员账户存在<br>";
    echo "账户信息：<br>";
    echo "ID: " . $admin['id'] . "<br>";
    echo "用户名: " . $admin['username'] . "<br>";
    echo "角色: " . $admin['role'] . "<br>";
} else {
    echo "<br>❌ 管理员账户不存在<br>";
} 